Fix duration_since panic on unix when std is built with integer overflow checks#146556
Fix duration_since panic on unix when std is built with integer overflow checks#146556bors merged 1 commit intorust-lang:masterfrom
Conversation
87b71c0 to
f335c20
Compare
This comment has been minimized.
This comment has been minimized.
|
Seems like the bug was there before constify of |
|
If anyone is around, not do I compile std with debug assertions including integer overflow? I'm running and such assertions are not triggered. |
|
put this in your bootstrap.toml rust.debug-assertions-std = truefrom Lines 603 to 604 in 52618eb |
|
|
|
Found it. |
f335c20 to
9cc8046
Compare
|
Ah, yes, down a few lines then. |
|
r? libs |
9cc8046 to
162ee46
Compare
This comment has been minimized.
This comment has been minimized.
|
Ping @tgross35. |
library/std/src/sys/pal/unix/time.rs
Outdated
| } else { | ||
| ( | ||
| (self.tv_sec - other.tv_sec - 1) as u64, | ||
| (self.tv_sec - 1).wrapping_sub(other.tv_sec) as u64, |
There was a problem hiding this comment.
I had to think for a few seconds before I realised why the - 1 couldn't panic (since other.tv_nsec is larger than self.tv_nsec, but other smaller than self, other.tv_sec must be smaller than self.tv_sec, meaning that there is a value smaller than self.tv_sec, making the subtraction work). Could you perhaps add a comment to explain it? Or use wrapping_sub for the decrement as well?
There was a problem hiding this comment.
I added a few assertions, so that sequence of assertion will explain why it does not underflow.
Or use wrapping_sub for the decrement as well?
That would not be right, because if there is a bug here, instead of debug assertion, we may quietly get wrong result.
library/std/src/sys/pal/unix/time.rs
Outdated
| @@ -150,12 +150,12 @@ impl Timespec { | |||
| // directly expresses the lower-cost behavior we want from it. | |||
There was a problem hiding this comment.
The comment above here needs to be updated, considering it specifically calls out self.tv_sec - 1 - other.tv_sec vs. self.tv_sec - other.tv_sec - 1. I don't think it's all relevant anymore, given https://rust.godbolt.org/z/1Ex913qr5
There was a problem hiding this comment.
I removed the comment because:
- you asked to update it
- I don't understand it
- this does not seem like performance critical code to do
Hey, this was open for only three days :) I don't think this is high priority? |
162ee46 to
8d641ba
Compare
This comment has been minimized.
This comment has been minimized.
The bugfix is not high priority, but I wanted to add a couple PRs on top, and if each one takes weeks to review, I will lose context and/or switch to some other work (my primary work is far from opensource). Sorry for the ping. Is there expected time to a comment from the reviewer for a PR in rust repo so next time I'll avoid pinging the maintainers too early? |
|
The comment that the bot posts for new contributors says
|
There was a problem hiding this comment.
Thanks for submitting this fix, two small requests then r=me.
The bugfix is not high priority, but I wanted to add a couple PRs on top, and if each one takes weeks to review, I will lose context and/or switch to some other work (my primary work is far from opensource).
Sorry for the ping. Is there expected time to a comment from the reviewer for a PR in rust repo so next time I'll avoid pinging the maintainers too early?
No worries, we just usually expect a couple of weeks. If you have a small change, it's fine to ask on Zulip if there's anyone willing to take a quick look at something.
I think stacking PRs is pretty common to keep future work unblocked.
8d641ba to
dfc3e3e
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Applied suggestions. Added helper function And slight offtopic here, that is the function I needed a few times: shouldn't it it added to core? Something like: This function would be somewhat similar to |
|
Looks great, thanks! |
dfc3e3e to
92859e9
Compare
|
... last minute typo in comment fix. |
|
@bors r+ |
|
@bors rollup |
Rollup of 7 pull requests Successful merges: - #146556 (Fix duration_since panic on unix when std is built with integer overflow checks) - #146679 (Clarify Display for error should not include source) - #146753 (Improve the pretty print of UnstableFeature clause) - #146894 (Improve derive suggestion of const param) - #146950 (core: simplify `CStr::default()`) - #146958 (Fix infinite recursion in Path::eq with String) - #146971 (fix ICE in writeback due to bound regions) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - #146556 (Fix duration_since panic on unix when std is built with integer overflow checks) - #146679 (Clarify Display for error should not include source) - #146753 (Improve the pretty print of UnstableFeature clause) - #146894 (Improve derive suggestion of const param) - #146950 (core: simplify `CStr::default()`) - #146958 (Fix infinite recursion in Path::eq with String) - #146971 (fix ICE in writeback due to bound regions) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146556 - stepancheg:repro-146228, r=tgross35 Fix duration_since panic on unix when std is built with integer overflow checks Add a test for regression #146228, and turns out this test fails detects error when std is compiled with integer overflow checks. Original regression was reverted in #146473. First attempt to fix was in #146247; test and some code is copied from there, thanks `@eval-exec` r? `@RalfJung`
Rollup of 7 pull requests Successful merges: - rust-lang/rust#146556 (Fix duration_since panic on unix when std is built with integer overflow checks) - rust-lang/rust#146679 (Clarify Display for error should not include source) - rust-lang/rust#146753 (Improve the pretty print of UnstableFeature clause) - rust-lang/rust#146894 (Improve derive suggestion of const param) - rust-lang/rust#146950 (core: simplify `CStr::default()`) - rust-lang/rust#146958 (Fix infinite recursion in Path::eq with String) - rust-lang/rust#146971 (fix ICE in writeback due to bound regions) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#146556 (Fix duration_since panic on unix when std is built with integer overflow checks) - rust-lang#146679 (Clarify Display for error should not include source) - rust-lang#146753 (Improve the pretty print of UnstableFeature clause) - rust-lang#146894 (Improve derive suggestion of const param) - rust-lang#146950 (core: simplify `CStr::default()`) - rust-lang#146958 (Fix infinite recursion in Path::eq with String) - rust-lang#146971 (fix ICE in writeback due to bound regions) r? `@ghost` `@rustbot` modify labels: rollup
Add a test for regression #146228, and turns out this test fails detects error when std is compiled with integer overflow checks.
Original regression was reverted in #146473.
First attempt to fix was in #146247; test and some code is copied from there, thanks @eval-exec
r? @RalfJung